<?php
 function new_array_diff( $arraya, $arrayb )   
     { 
     $intersection = array_intersect( $arraya, $arrayb ); 
     foreach( $arraya as $keya => $valuea )
         {
            if ( !isset($intersection[$keya]) )
              {
               $diff[$keya] = $valuea;
               }
           } 
      return $diff;    
    }
class DefaultController extends Controller
{
    public function actionIndex()
    {
	
       $refNumArray = Yii::app()->dbqb->createCommand('select RefNumber,subtotal from invoice  ')
           ->queryAll();
        $refResult = array();
        foreach ($refNumArray as $item){
            $refResult[] = $item['RefNumber'];
        }


       $invArray =  Yii::app()->db->createCommand('select invoice,amountcharge
                                                   from tbl_invoice
                                                   where invoicetype = "Invoice" and custno!="0000235"
                                                   order by invoice')
           ->queryAll();
            
        $invResult = array();
        foreach ($invArray as $item){
            $invResult[] = $item['invoice'];
        }
   
        $uniq_invoices = new_array_diff($invResult,$refResult);
  
        echo CHtml::tag('h3',array(),'Invoices Not found in Quickbooks:');
        foreach($uniq_invoices as $inv){
			$model = Invoice::model()->findByPk($inv);
            echo $inv.' '.$model->getHoldText().'<br/>';
        }
           die();
        $qbInvList = array();
        foreach ($refNumArray as $item){
            $qbInvList[$item['RefNumber']] = $item['subtotal'];
        }
        $ccInvList = array();
        foreach ($invArray as $item){
            $ccInvList[$item['invoice']] = $item['amountcharge'];
        }
        echo CHtml::tag('h3',array(),'CC Invoice Total != Quickbooks Amount Total');
           die();
        ?>
    <table>
    <thead>
    <tr>
    <th>Invoice</th>
    <th>CC</th>
    <th>QB</th> 
    </tr>
    </thead>
               
	
        <? 
        foreach ($ccInvList as $invoice=>$amount):
			$qb_amount = Yii::app()->dbqb->createCommand("SELECT SUM( invoicelinedetail.rate ) 
FROM invoice
INNER JOIN invoicelinedetail ON invoice.TxnID = invoicelinedetail.IDKEY
WHERE invoice.RefNumber =  '$invoice'")
           ->queryScalar();
           echo $invoice;
     
            if(isset($qbInvList[$invoice] ) && $amount!=$qb_amount ):?>
            <tr>
				<td>
             <?=$invoice?> 
				</td>
				<td align="right">
				<?=$amount?> 
				</td>
				<td  align="right">
				 <?=$qb_amount?>
				</td>
             </tr>
		<?php
		endif;
		endforeach;
	echo' </table>';
    }
}
?>
